import { visit } from 'unist-util-visit'

export default function () {
  return (tree: any) => {
    visit(tree, function (node) {
      if (
        node.name === "HiddenText"
      ) {
        if (node.children[0].type !== "text") {
          // move all text into the first child
          node.children = [
            {
              type: 'text',
              value: node.children[0].children.map((child: any) => child.value).join('')
            }
          ]
        }
      }
    })
  }
}